package Offer.offer;

/**
 * 和为s的连续正数序列
 * Created by 雷文康 on 2018/1/6.
 */
public class Test41b和为S的连续正数序列 {
    public static void main(String[] args) {
        find(15);
    }
    public static void find(int s){
        if (s < 3) {
            return;
        }
        int start = 1;
        int end = 2;
        int sum = start + end;
        while (start <= s / 2) {
            if (sum == s) {
                for (int i = start; i <= end; i++) {
                    System.out.print(i);
                    System.out.print(" ");
                }
                System.out.println();
                sum -= start;
                start++;
            } else if (sum < s){
                end++;
                sum += end;
            } else {
                sum -= start;
                start++;
            }
        }
    }


}
